<template>
  <div class="wrapper" ref="wrapper">
    <div class="content">
      <slot></slot>
    </div>
  </div>
</template>

<script>
  import Bscroll from 'better-scroll'
  export default {
    name: "scroll",
    props:{
      probeType: 0,
      pullUpLoad: false
    },
    data(){
      return{
        scroll: null
      }
    },
    mounted(){
      //创建bscroll对象
      this.scroll = new Bscroll(this.$refs.wrapper, {
        click: true,
        probeType: this.probeType,
        pullUpLoad: this.pullUpLoad
      })

      //监听位置
      this.scroll.on('scroll',position =>{
        // 将位置发射
        this.$emit('scroll',position);
      })

      this.scroll.on('pullingUp', () => {
        this.$emit('pullingUp')
      })
    },
    methods:{
      //返回最上层方法，供给父组件调用
      scrollTo(x,y, time=300){
        this.scroll.scrollTo(x,y,time)
      },
      scrollFinsh(){
        this.scroll.finishPullUp()
      },
      scrollRefresh(){
        this.scroll.refresh()
      }
    }
  }
</script>

<style scoped>

</style>
